package com.njts.servlet;

import com.njts.auto.AutoCreateBean;
import com.njts.auto.AutoSearch;
import com.njts.bean.Subject;
import com.njts.dao.UseDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@WebServlet("/subjectSelect")
public class SubjectSelectServlet extends HttpServlet {
    AutoCreateBean autoCreateBean=new AutoCreateBean();
    AutoSearch autoSearch=new AutoSearch();
    UseDao useDao=new UseDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        Subject subject=new Subject();
        String whereComplementSql;
        try {
            subject =(Subject) autoCreateBean.createBean(req,subject);
            whereComplementSql= autoSearch.getWhereComplementSql(subject);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        List<Subject> subjectList = useDao.selectSubject(whereComplementSql);
        //
        req.setAttribute("subjectList",subjectList);
        req.setAttribute("subjectCount",20); //先写死后面改
        req.getRequestDispatcher("/view/subject.jsp").forward(req,resp);


    }
}
